package cc.fs.study.Image;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cc.fs.study.R;

public class ImageActivity extends AppCompatActivity {

    ImageView image1,image2;
    TextView textView1,textView2;
    Bitmap srcBitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image);

        image1 = (ImageView)findViewById(R.id.image1);
        image2 = (ImageView)findViewById(R.id.image2);
        textView1 = (TextView)findViewById(R.id.text1);
        textView2 = (TextView)findViewById(R.id.text2);
        srcBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.bg);
        textView1.setText("长:"+srcBitmap.getWidth()+"\n宽:"+srcBitmap.getHeight());
    }

    public void covert(View view){
       new CompessThread().execute(srcBitmap);
    }

    class CompessThread  extends AsyncTask<Bitmap,Void,Bitmap>{

        @Override
        protected Bitmap doInBackground(Bitmap... params) {
            return ImageUtil.zoomImage(params[0]);
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            image2.setImageBitmap(bitmap);
            textView2.setText("长:"+bitmap.getWidth()+"\n宽:"+bitmap.getHeight());
        }
    }
}
